<template>
  <div class="bgff p20">
    <em>
      <el-button  size="medium" type="primary" @click="addNet">添加岗位</el-button>
      <edit :is_edit="false" ref="form" :cur_this="cur_this"></edit>
    </em>
    <el-table
      :data="tableData"
      v-loading="loading"
      row-key="id"
      border
      style="width: 100%;margin-top:20px;"
      default-expand-all
      empty-text="暂无数据"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column
        type="index"
        width="50"
        :index="(index)=>{return (index+1) + (curPage - 1) * size }"
        label="序号"
      ></el-table-column>
      <el-table-column prop="name" label="岗位名称" min-width="150"></el-table-column>
     <!-- <el-table-column prop="createTime" label="状态" min-width="120">
        <template slot-scope="scope">
          <em style="color:green" v-if="scope.row.enabled">启用</em>
          <em style="color:#a11" v-else>禁用</em>
        </template>
      </el-table-column>-->
      <el-table-column prop="dept.name" label="所属部门" min-width="120"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" min-width="120">
         <template slot-scope="scope">
            {{new Date(scope.row.createTime).format('yyyy-MM-dd hh:mm:ss')}}
          </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <em>
            <el-button @click="editClick(scope.row)" type="text" size="small">编辑</el-button>
            <edit :is_edit="true" :cur_this="cur_this" ref="edform"></edit>
          </em>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="mt20"
      @current-change="handlePage"
      @size-change="handleSizeChange"
      :current-page.sync="curPage"
      :page-size="size"
      :page-sizes="[5,10]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>

<script>
import edit from "./modul/edit";
import { _jobList, _jobDelete, _deptList } from "@/http/ajax";
export default {
  components: { edit },
  data() {
    return {
      cur_this: this,
      loading: false,
      tableData: [],
      depts: [],
      curPage: 1,
      size: 10,
      total: 0
    };
  },
  created() {
    this.getList();
    _deptList(
      {},
      res => {
        this.depts = res.content;
      },
      err => {}
    );
  },
  methods: {
    editClick(row) {
      const _this = this.$refs.edform;
      _this.dialog = true;
      _this.form = {
        name: row.name,
//        enabled: row.enabled,
        sort: row.sort,
        id: row.id,
        dept: { id: row.dept.id }
      };
      _this.depts = this.depts;
      _this.domInit();
    },
    addNet() {
      const _this = this.$refs.form;
      _this.dialog = true;
      _this.depts = this.depts;
      _this.domInit();
      if(sessionStorage.level==2){
         _this.form.dept.id = this.depts[0].id
      }
    },
    // 处理部门分类
    deptDo() {
      if(sessionStorage.level==1){
        return [
          {
            createTime: null,
            enabled: true,
            id: 0,
            label: "admin",
            pid: 0,
            children: this.depts
          }
        ];
      }else if(sessionStorage.level==2){
        let label = this.depts[0].label
        let a = [{
            createTime: null,
            enabled: true,
            id: 0,
            label: label,
            pid: 0,
            children: []
          }]
          return this.depts;
      }
    },
    // 获取banner列表
    getList(page) {
      this.tableData = [];
      this.loading = true;
      let data = {
        page: this.curPage - 1,
        size: this.size,
        sort: null
      };
      _jobList(
        data,
        res => {
          setTimeout(() => {
            this.loading = false;
            this.total = res.totalElements;
            this.tableData = res.content;
          }, 300);
        },
        err => {
          this.loading = false;
        }
      );
    },
    del(id) {
      _jobDelete(
        id,
        res => {
          this.getList();
        },
        err => {}
      );
    },
    // 切换页码
    handlePage(val) {
      this.curPage = val;
      this.getList();
    },
    // 切换条数
    handleSizeChange(val) {
       this.curPage = 1;
      this.size = val;
      this.getList();
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
